#include<stdlib.h>
#include<stdint.h>
#include<math.h>
#include<assert.h>
#include<time.h>
#include "utils.h"

int count_chars(const char *string, char ch)
{
    int count = 0;
    for(; *string; count += (*string++ == ch)) ;
        return count;
}

uint32_t my_ntohl(const void *buf)
{
    uint32_t return_val = 0, i;

    assert(buf + 3 != NULL);
    for (i = 0; i < 4; i++)
        return_val += *(uint8_t *)(buf + i) * pow(256, 3 - i);
    
    return return_val;
}

int my_rand(int n)
{
    srand((unsigned)time(NULL));
    return rand()%(n);
}
